import Vue from 'vue'
import router from './router/router'
import store from './vuex/store'
import App from './App'
import myMixin from './commonjs/vuePrototype';
window.Driver = (require('@/commonjs/drivers.js')).h5_native_proxy;
window.apiConfig = (require('@/commonjs/apiConfig.js')).apiConfig;
window.commonObj = (require('@/commonjs/common.js')).commonObj;
import '@/commonjs/vuePrototype.js';
import 'element-ui/lib/theme-chalk/index.css';
// 引入jq解决swiper报错问题
require("./commonjs/jquery")
window.commonObj.loadPubModule()
//扩展前端监控
// const errorHandler = (error, vm) => {
//     console.log(error);
// }
// Vue.config.errorHandler = errorHandler;
// function loadPubModule() {
//     const requireComponent = require.context('@/components/', false, /\.vue$/);
//     requireComponent.keys().forEach(fileName => {
//         const componentConfig = requireComponent(fileName);
//         const componentName = capitalizeFirstLetter(fileName.replace(/^\.\//, '').replace(/\.\w+$/, ''));
//         Vue.component(componentName, componentConfig.default || componentConfig);
//     })
//     function capitalizeFirstLetter(string) {
//         return string.charAt(0).toUpperCase() + string.slice(1);
//     }
// }
// loadPubModule()
// Vue.prototype.$throw = (error) => errorHandler(error, this);

router.beforeEach((to, from, next) => {
  var fromName = from.meta.title || 'XX bank';
  if (to.matched.some(record => record.meta.requiresAuth || false)) {
    if (!sessionStorage.getItem("userinfo")) {
      next({
        path: '/login',
        query: { redirect: to.fullPath }
      })
    } else {
      next();
    }
  } else {
    next();
  }
})
router.afterEach((transition) => {

})

new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})

